package org.example.baizhi;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.Tuple;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class TestRedisCluster {
    public static void main(String[] args) {
        HashSet<HostAndPort> hostAndPort = new HashSet<>();
        hostAndPort.add(new HostAndPort("192.168.1.100", 7000));
        hostAndPort.add(new HostAndPort("192.168.1.100", 7001));
        hostAndPort.add(new HostAndPort("192.168.1.100", 7002));
        hostAndPort.add(new HostAndPort("192.168.1.100", 7003));
        hostAndPort.add(new HostAndPort("192.168.1.100", 7004));
        hostAndPort.add(new HostAndPort("192.168.1.100", 7005));
        hostAndPort.add(new HostAndPort("192.168.1.100", 7006));

        JedisCluster jedisCluster = new JedisCluster(hostAndPort);

        //操作String
        String name = jedisCluster.get("name");
        System.out.println(name);
        jedisCluster.set("name","cyt");

        //操作List
        // Long lpush = jedisCluster.lpush("name", "cyt", "list", "wangwu");
        // List<String> naems = jedisCluster.lrange("name", 0, -1);
        // for (String s : naems) {
        //     System.out.println(s);
        // }

        //操作set
        // jedisCluster.sadd("ages","12","23","34");
        // Set<String> ages1 = jedisCluster.smembers("ages");
        // for (String s : ages1) {
        //     System.out.println(s);
        // }


        // 操作Zset
        // HashMap<String,Double> scoreMembers = new HashMap<>();
        // scoreMembers.put("cyt", 12.0);
        // scoreMembers.put("wangwu", 23.0);
        // jedisCluster.zadd("zset",scoreMembers);
        //
        // Set<Tuple> zset = jedisCluster.zrangeWithScores("zset", 0, -1);
        // for (Tuple tuple : zset) {
        //     System.out.println(tuple.getElement()+"score"+tuple.getScore());
        // }

        //操作hash

        Long hset = jedisCluster.hset("maps", "name", "cyt");
        String hget = jedisCluster.hget("maps", "name");
        System.out.println(hget);
    }
}
